package org.academic.texteditor.gui.component.listener;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

public class ParagraphTransferable implements Transferable {

	protected static DataFlavor paragraphFlavor = new DataFlavor(String.class, "Paragraph");
	protected static DataFlavor[] supportedFlavors = { paragraphFlavor };
	
	private final String paragraph;

	public ParagraphTransferable(String paragraph) {
		this.paragraph = paragraph;
	}

	@Override
	public Object getTransferData(DataFlavor flavor)
			throws UnsupportedFlavorException, IOException {
		
		if (paragraphFlavor.equals(flavor) && paragraphFlavor.getHumanPresentableName().equals(flavor.getHumanPresentableName())) {
			return paragraph;
		}
		
		throw new UnsupportedFlavorException(flavor);
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		return supportedFlavors;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		return paragraphFlavor.equals(flavor);
	}

}
